package com.cdm.domain.dao;

import java.util.List;

import com.cdm.persistence.User;

/**
 * File: SequenceDAO
 * <P>
 * Description: -none-
 * <P>
 * <B>Change History :</B>
 * <P>
 * <ul>
 * <li>2008-3-8 Created by vivo</li>
 * </ul>
 * 
 * @author GaoBo
 */
public class UserDAO extends GenericDaoSupport<User> {
	public static final String EMAIL = "email";
	public static final String LOGIN_NAME = "loginName";
	public static final String PASSWORD = "password";
	public static final String PHONE = "phone";
	public static final String AUTH_STATUS = "authStatus";
	public static final String USER_NAME = "userName";
	public static final String USER_ID = "userId";
	public static final String USER_ROLE = "userRole";

	public List<User> findByEmail(Object email, int... rowStartIdxAndCount) {
		return findByProperty(EMAIL, email, rowStartIdxAndCount);
	}

	public User findByLoginAndPassword(String loginName, String password) {
		User result = null;
		try {
			result = (User) getEntityManager().createQuery(
			        "select user from User user where user.loginName=? and user.password=?").setParameter(1, loginName)
			        .setParameter(2, password).getSingleResult();
		} catch (RuntimeException e) {
			e.printStackTrace();
		}
		return result;
	}


}